home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / PowerPC / vbcc / machines / amigawos / libsrc / AmigaLib / RangeRand.c < prev    next >
C/C++ Source or Header  |  1998-08-02  |  316b  |  19 lines

  1. #include <exec/types.h>
  2.  
  3. ULONG RangeSeed;
  4.  
  5. ULONG RangeRand(ULONG maxValue)
  6. { ULONG a=RangeSeed;
  7.   UWORD i=maxValue-1;
  8.   do
  9.   { ULONG b=a;
  10.     a<<=1;
  11.     if((LONG)b<=0)
  12.       a^=0x1d872b41;
  13.   }while((i>>=1));
  14.   RangeSeed=a;
  15.   if((UWORD)maxValue)
  16.     return (UWORD)((UWORD)a*(UWORD)maxValue>>16);
  17.   return (UWORD)a;
  18. }
  19.